package com.xpgk.sbwx.login;

import com.jfinal.kit.StrKit;
import com.jfinal.log.Log;
import com.xpgk.constant.ConstantRender;
import com.xpgk.constant.ConstantWebContext;
import com.xpgk.mvc.base.BaseController;
import com.xpgk.mvc.bentryRegister.Customer;
import com.xpgk.mvc.login.LoginService;
import com.xpgk.mvc.user.User;
import com.xpgk.tools.ToolWeb;

/**
 * 登陆处理
 */
public class WXLoginController extends BaseController {

	private static final Log log = Log.getLog(WXLoginController.class);

	private WXLoginService loginService;

	/**
	 * 准备登陆
	 */
	public void index() {
		
		render("/sbwx/wxlogin.jsp");
		
		
	}

	/**
	 * 绑定验证
	 */
	
	public void saveCus(){
		String openid = getPara("openid");
		String phone = getPara("phone");
		String msg = "200";
		String sql = "SELECT * FROM sb_customer where phone = ? AND dataStatus in ('1','2')";
		String sql2 = "SELECT * FROM sb_customer where openid = ? AND dataStatus in ('1','2')";
		Customer cus = Customer.dao.findFirst(sql,phone);
		Customer cus2 = Customer.dao.findFirst(sql2,openid);
		if(cus2!=null){
			msg = "该微信号已经绑定顾客！";
		}else{
			if(cus!=null){
				if(cus.getStr(Customer.column_openid)!=null && !cus.getStr(Customer.column_openid).equals("")){
					msg = "该顾客已经绑定过微信号";
				}else{
					cus.set(Customer.column_openid, openid);
					if(!cus.update()){
						msg = "更新失败";
					}
				}
				
				
			}else{
				msg = "该手机号的主人暂时还不是瘦吧的顾客哦";
			}
		}
		
		
		renderText(msg);
	}
	
}
